<?php
namespace app\admin\controller;

class Featured extends Base
{
    private $obj;
    public function _initialize()
    {
        $this->obj = model('Featured');
    }

    public function index(){
        $types = config('featured.featured_type');
        $type = input('get.type',0,'intval');
        //获取推荐位列表数据
        $featureds = $this->obj->getFeaturedsByType($type);
        return $this->fetch('',[
            'types' => $types,
            'featureds' => $featureds,
            'type' => $type,
        ]);
        // $featured = $this->obj->get
    }

    public function add(){
        if(request()->isPost()){
            $data = input('post.');
            //数据需要做严格校验
            $id = model('Featured')->add($data);
            if($id){
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }else{
            $types = config('featured.featured_type');
            return $this->fetch('',[
                'types' => $types,
            ]);
        }
    }

    //排序和编辑

    // public function status(){
    //     $data = input('get.');
    //     //校验数据

    //     $res = $this->obj->save(['status'=>$data['status']],['id'=>$data['id']]);
    //     if($res){
    //         $this->success('更新成功');
    //     }else{
    //         $this->error('更新失败');
    //     }
    // }


}
